/*
 * 作者: 侯晓宇
 * 时间: 2017-03-30
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {

	require("jquery");

	var c = require('app/utils/CommonUtils');
	var appInfo = require('app/AppInfo');
	var UserInfoUtils = require('app/utils/UserInfoUtils');
	var RoomInfoUtils = require('app/utils/RoomInfoUtils');
	var EventUtils = require('app/utils/EventUtils');
	var hc = require('app/utils/HttpClientUtils');
	var param = api.pageParam;
	var dialog = new auiDialog({})
	
	
	function save(){
		var url = appInfo.serverbase + "/luyan/room/" + param.uuid + "/pwdsave";
		var body = {
			pwd : $("#pwd").val()
		}
		hc.post(url, body, function(resp) {
			if (resp.status == "200") {
				EventUtils.send('IndexMeMyRoomWin', 'refresh_my_room');
				api.closeWin({
				});
			}
		});
	}
	function tips() {
		dialog.alert({
			title : "是否保存此授权密码",
			msg : ''+$("#pwd").val(),
			buttons : ['暂不保存', '保存']
		}, function(ret) {
			if (ret) {
				if(ret.buttonIndex == 2){
					save();
				}
			}
		})
	}


	$("#title").text(param.name);
	$("#back").click(function() {
		api.closeWin({
		});
	});
	$("#genpwd").click(function() {
		$("#pwd").val(c.random(4));
		tips();
	});
	$("#pwd").val(param.pwd);

	$("#save").click(function() {
		save();
	});

	return;
});
